package com.coding365.consumer.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.coding365.api.ServiceApiA;
import com.coding365.api.ServiceApiB;
import com.coding365.api.ServiceApiC;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@RestController
@RequestMapping("/dubbo")
public class ConsumerController {

    @Reference
    private ServiceApiA serviceApiA;

    @Reference
    private ServiceApiB serviceApiB;

    @Reference
    private ServiceApiC serviceApiC;



    @GetMapping("/test")
    public void test(){

        ExecutorService cachedThreadPoolA = Executors.newCachedThreadPool();

        for (int i = 0;i < 30;i++){
            cachedThreadPoolA.execute(() -> {
                while (true){
                    serviceApiA.methodA();
                }
            });
        }

        ExecutorService cachedThreadPoolB = Executors.newCachedThreadPool();

        for (int i = 0;i < 30;i++){
            cachedThreadPoolB.execute(() -> {
                while (true){
                    serviceApiB.methodB();
                }
            });
        }

        ExecutorService cachedThreadPoolC = Executors.newCachedThreadPool();

        for (int i = 0;i < 30;i++){
            cachedThreadPoolC.execute(() -> {
                while (true){
                    serviceApiC.methodC();
                }
            });
        }

    }
}
